<?php
declare (strict_types = 1);

namespace app\api\model\v1;

use app\api\helpers\Tree;
use think\Model;

/**
 * @mixin \think\Model
 */
class AuthWxMenu extends Model
{
    //
    public function wxMenu(){
        return $this->belongsTo(WxMenu::class,'wx_menu_id');
    }

    /**
     * Notes:
     * User: liuhailong
     * DateTime: 2022/4/20 15:02
     * @param $id
     * @param $category
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * 查找父级
     */
    public static function findWxMenu($id,$category){
        $res = self::field('id')->where(['unit_id'=>$id])->select()->toArray();
        if(empty($res)){
            $aaa = $category->getParent($id);
            if(!empty($aaa)){
                $res =  self::findWxMenu($aaa[0]['id'],$category);
            }
        }

        return $res;
    }
}
